var gulp = require('gulp');
var clean = require('gulp-clean');
var uglify = require('gulp-uglify');
var rev = require('gulp-rev');
var revCollector = require('gulp-rev-collector');
var minifyHTML = require('gulp-minify-html');
var del = require('del');
var concat = require('gulp-concat');

gulp.task('rev', ['mv-scripts'], function() {
    return gulp.src([__dirname + '/dist/rev/js/*.json', __dirname + '/dist/tmp-views/*.html'])
        .pipe(revCollector())
        .pipe(gulp.dest(__dirname + '/dist/views/'));
});

gulp.task('mv-scripts', ['mv-views'], function() {
    return gulp.src(__dirname + '/src/scripts/*.js')
        .pipe(uglify())
        .pipe(rev())
        .pipe(gulp.dest(__dirname + '/dist/scripts/'))
        .pipe(rev.manifest())
        .pipe(gulp.dest(__dirname + '/dist/rev/js'));
});

gulp.task('mv-views', ['mv-libs'], function() {
    return gulp.src(__dirname + '/src/views/*.html')
        .pipe(gulp.dest(__dirname + '/dist/tmp-views/'));
});

gulp.task('mv-libs', function() {
    return gulp.src(__dirname + '/src/libs/**')
        .pipe(gulp.dest(__dirname + '/dist/libs/'));
});

gulp.task('concat-libs', function() {
    return gulp.src([],
        __dirname + '/src/scripts/*.js');
});

gulp.task('clean', function() {
    gulp.src(__dirname + '/dist/')
        .pipe(clean());
});

gulp.task('build', ['rev'], function() {
    del([
        __dirname + '/dist/rev',
        __dirname + '/dist/tmp-views'
    ]);
});

gulp.task('lib', function() {
    gulp.src(__dirname + '/dep/vue/dist/vue.min.js')
        .pipe(gulp.dest(__dirname + '/src/libs/vue/'));
    gulp.src(__dirname + '/dep/axios/dist/axios.min.js')
        .pipe(gulp.dest(__dirname + '/src/libs/axios/'));
    gulp.src(__dirname + '/dep/amazeui/dist/**')
        .pipe(gulp.dest(__dirname + '/src/libs/amazeui/'));
    gulp.src(__dirname + '/dep/jquery/dist/jquery.min.js')
        .pipe(gulp.dest(__dirname + '/src/libs/jquery/'));
    gulp.src(__dirname + '/dep/lodash/dist/lodash.min.js')
        .pipe(gulp.dest(__dirname + '/src/libs/lodash/'));
});